﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Xml.Serialization;

namespace TddGenerator.Core.Services.Impl
{
    public class XmlFileSerializer<T>:ISerializer<T>
    {
        public void Serialize(T value,string filename)
        {
            // Serialization
            XmlSerializer s = new XmlSerializer(typeof(T));
            TextWriter w = new StreamWriter(filename);
            s.Serialize(w, value);
            w.Close();
        }

        public T Deserialize(string filename)
        {
            XmlSerializer s = new XmlSerializer(typeof(T));
            TextReader r = new StreamReader(filename);
            T returnObject = (T) s.Deserialize(r);
            r.Close();
            return returnObject;
        }
    }
}
